<template>
	<view class="">
		<view class="common-list animated fadeIn fast">
			<view class="common-list-hd u-f-ac">
				<image class="hd-lt" :src="item.user.avatar" @tap.stop="openSpace" lazy-load></image>
				<view class="hd-rt">
					<view class="author">
						{{item.user.nickname}}
					</view>
					<view class="time">
						{{item.publish_at}}
					</view>
				</view>
			</view>

			<view class="common-list-content">
				<view class="" @tap.stop="opendetail">
					<template v-if="item.multimedia.cover.url">
						<!-- 图片 -->
						<image :src="item.multimedia.cover.url" mode="widthFix" style="height: 350upx;" lazy-load></image>
					</template>
				</view>
				<slot name="tags"></slot>
				<view class="desc" @tap.stop="opendetail">{{item.summary}}</view>

				<view v-if="!isWorkDetail" class="opts u-f-ac u-f-jsb">
					<view class="opts-lt u-f-ac">
						<view class="icon iconfont iconfenxiang">
						</view>转发
					</view>
					<view class="opts-rt u-f-ac">
						<view class="icon iconfont iconpinglun">
						</view>评论
						<view class="icon iconfont iconxihuan" @tap="caozuo('ding')">
						</view>{{item.zanNum}}
					</view>
				</view>

			</view>
		</view>
		
	</view>

</template>

<script>
		
	export default {
		components: {
		},
		props: {
			nonavigate: {
				type: Boolean,
				default: false
			},
			item: Object,
			index: Number,
			isWorkDetail: {
				type: Boolean,
				default: false
			}
		},
		computed: {
			getSex() {
				return this.item.sex;
			},
			getAge() {
				return this.item.age;
			}
		},
		methods: {
			async guanzhu() {
				try {
					let [err, res] = await this.$http.post('/follow', {
						follow_id: this.item.userid
					}, {
						token: true,
						checkToken: true,
						checkAuth: true
					});
					// 错误处理
					if (!this.$http.errorCheck(err, res)) return;
					// 通知首页修改数据
					uni.showToast({
						title: '关注成功'
					});
					let resdata = {
						type: "guanzhu",
						userid: this.item.userid,
						data: true
					};
					// 通知父组件
					this.$emit('changeevent', resdata);
					// 通知全局
					uni.$emit('updateData', resdata);
				} catch (e) {
					return;
				}
			},
			// 进入详情页
			opendetail() {
				uni.navigateTo({
					url: 'work/work_detail/work_detail?detailData=' + JSON.stringify(this.item),
				});
				// this.User.addHistoryList(this.item);
			},
			async caozuo(type) {
				let index = (type === 'ding') ? 1 : 2; // 当前操作
				let [err, res] = await this.$http.post('/support', {
					post_id: this.item.id,
					type: index - 1
				}, {
					token: true,
					checkToken: true,
					checkAuth: true
				});
				if (!this.$http.errorCheck(err, res)) return;
				uni.showToast({
					title: "顶成功"
				});
				// 通知父组件
				let resdata = {
					type: "support",
					post_id: this.item.id,
					do: type
				};
				this.$emit('changeevent', resdata);
				// 通知全局
				return uni.$emit("updateData", resdata);
			},
			openSpace() {
				if (this.nonavigate) return;
				uni.switchTab({
					url: "me/me?userid=" + this.item.userid
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.common-list {
		padding: 32upx 32upx 0;
		background-color: #fff;
	}

	.common-list-hd {
		>image {
			width: 80upx;
			height: 80upx;
			border-radius: 50%;
			margin-right: 16upx;
		}

		.author {
			font-weight: 400;
			color: $b1;
			line-height: 45upx;
			font-size: 32upx;
		}

		.time {
			font-size: 28upx;
			font-weight: 400;
			color: rgba(140, 140, 140, 1);
			line-height: 40upx;
		}
	}


	.common-list-content {
		margin-top: 17upx;
		padding-bottom: 20upx;
		border-bottom: 1upx solid #EEEEEE;

		>view:nth-child(3)>image {
			width: 100%;
			border-radius: 10upx;
		}

		>view:nth-child(1) {
			image {
				width: 686upx;
				height: 686upx;
			}
		}

		>view:nth-child(2) {
			font-size: 32upx;

		}

		.desc {
			color: #3F4345;
		}

		>.opts {
			>view {
				color: $b2;
				font-size: 28upx;
			}

			>view:nth-child(2)>view {
				margin-right: 10upx;
			}

			.icon {
				margin-right: 13upx;
			}

			.iconxihuan {
				margin-left: 41upx;
			}
		}
	}

	
</style>
